package com.example.spring3.bank;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class OrderTest {

    public static void main(String[] args) throws Exception {
        //构建简单商品优惠信息
        List<GoodsCoupon> goodsCoupon = buildGoodsCouponList();
        //构建简单的订单优惠信息
        OrderCoupon orderCoupon = buildOrderCounpon();
        OrderService orderService = new OrderService(goodsCoupon, orderCoupon);
        List<Goods> goodsList = buildGoodsList();
        //计算出最终的结果
        OrderInfo order = orderService.createOrder(goodsList);
    }

    private static OrderCoupon buildOrderCounpon() {
        OrderCoupon orderCoupon = new OrderCoupon();
        //满100减10
        orderCoupon.setCouponPrice(new BigDecimal(10));
        orderCoupon.setMinPrice(new BigDecimal(100));
        return orderCoupon;
    }

    private static List<GoodsCoupon> buildGoodsCouponList() {
        List<GoodsCoupon> goodsCouponList = new ArrayList<>();
        GoodsCoupon coupon = new GoodsCoupon();
        coupon.setGoodsId("002");
        coupon.setDiscountPercent(8.0);
        //折扣计算价格
        coupon.setDiscount(true);
        goodsCouponList.add(coupon);
        return goodsCouponList;
    }

    //构建测试数据
    private static List<Goods> buildGoodsList() {
        List<Goods> goodsList = new ArrayList<>();
        Goods apple = new Goods();
        apple.setId("001");
        apple.setOldPrice(new BigDecimal(8));
        apple.setNowPrice(new BigDecimal(8));
        apple.setKg(10.0);
        apple.setGoodName("苹果");


        Goods strawberry = new Goods();
        strawberry.setId("002");
        strawberry.setOldPrice(new BigDecimal(13));
        strawberry.setNowPrice(new BigDecimal(13));
        strawberry.setKg(10.0);
        strawberry.setGoodName("草莓");


        Goods mango = new Goods();
        mango.setId("003");
        mango.setOldPrice(new BigDecimal(20));
        mango.setNowPrice(new BigDecimal(20));
        mango.setKg(10.0);
        mango.setGoodName("芒果");


        goodsList.add(apple);
        goodsList.add(strawberry);
        goodsList.add(mango);
        return goodsList;
    }
}
